package com.kalix.training.videos.dao;

import com.kalix.framework.core.impl.dao.GenericDao;
import com.kalix.training.videos.api.dao.IVideosBeanDao;
import com.kalix.training.videos.entities.VideosBean;
import org.apache.commons.collections.set.SynchronizedSet;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import java.io.Serializable;

public class VideosBeanDaoImpl extends GenericDao<VideosBean,Long> implements IVideosBeanDao {
    @Override
    @PersistenceContext(unitName = "training-videos-unit")
    public void setEntityManager(EntityManager em) {
        super.setEntityManager(em);
    }


    @Transactional
    public void auditBatch(String ids) {
        String strIds = ids;
        if (strIds != null && strIds.trim().length() > 0) {
            Object object;
            strIds = strIds.replaceAll(",", ":");
            strIds = strIds.replaceAll(";", ":");
            String[] arrayIds = strIds.split(":");
            for (int i = 0; i < arrayIds.length; i++) {
                if (arrayIds[i] != null && arrayIds[i].trim().length() > 0) {
//                    object =  get((super.PK)arrayIds[i]);
//                    entityManager.remove(object);
                }
            }
            entityManager.flush();
        }
    }
}
